# -*- coding: utf-8 -*-
from datetime import datetime
from django.db import models
from django.core.urlresolvers import reverse
from Colaboradores.models import Colaborador
from thumbs import ImageWithThumbsField
def content_image_name(instance, filename):
    return '/'.join(['arquivos/galeria', str(instance.sluggaleria), filename])
class Galeria(models.Model):
    publicar = models.BooleanField(default=True)
    manchete = models.BooleanField(default=False)
    titulo = models.CharField(max_length=100, unique=True)
    subtitulo = models.CharField(max_length=200)
    chamada = models.CharField(max_length=50)
    conteudo = models.TextField(blank=True, null=True)
    datapublicacao = models.DateTimeField(auto_now_add=True)
    fonte = models.CharField(max_length=20, blank=True, null=True)
    imagemDestaque = ImageWithThumbsField('Imagem Destaque', upload_to='arquivos/noticia/', sizes=((605,440),(117,88)))
    sluggaleria = models.SlugField(max_length=200, blank=True)
    autor = models.ForeignKey(Colaborador)
    hits = models.IntegerField('Cliques', default=0, editable=False)
    def __unicode__(self):
        return self.titulo
    def get_absolute_url(self):
        return reverse('slainte.views.galeria', kwargs={'sluggaleria': self.titulo})

class Imagem(models.Model):
    foto = ImageWithThumbsField('Imagem Destaque', upload_to='arquivos/galeria/', sizes=((918,573),(170,127)))
    nomeGaleria = models.ForeignKey(Galeria)

# SIGNALS
from django.db.models import signals
from django.template.defaultfilters import slugify

def galeria_pre_save(signal, instance, sender, **kwargs):
    instance.sluggaleria = slugify(instance.titulo)

signals.pre_save.connect(galeria_pre_save, sender=Galeria)